﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZYOPPC;
using ZYOPPC.基本概念;


namespace ZYOPPC
{
    public partial class FormDetails : Form
    {
        public FormDetails()
        {
            InitializeComponent();
        }

        private bool isZF;
        public bool 是否值符
        {
            get { return isZF; }
            set { isZF = value; }
        }

        private String theGod;
        public String 八神
        {
            get { return theGod; }
            set { theGod = value; }
        }

        private e八门 theDoor;
        public e八门 八门
        {
            get { return theDoor; }
            set { theDoor = value; }
        }

        private e九星[] theStar;
        public e九星[] 九星
        {
            get { return theStar; }
            set { theStar = value; }
        }

        private e三奇六仪[] theUpperQiYi;
        public e三奇六仪[] 天盘奇仪
        {
            get { return theUpperQiYi; }
            set { theUpperQiYi = value; }
        }

        private e三奇六仪[] theDownQiYi;
        public e三奇六仪[] 地盘奇仪
        {
            get { return theDownQiYi; }
            set { theDownQiYi = value; }
        }

        private e九宫数[] thePalace;
        public e九宫数[] 所处之宫
        {
            get { return thePalace; }
            set { thePalace = value; }
        }

        public int 局数;
        public e八门 值使;
        public e九星 值符;
        public ZYDateTime 当时八字;

        private void menuItemGoBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormDetails_Load(object sender, EventArgs e)
        {
            textBox1.Text = 当时八字.Name;
            AddALine(局数.ToString() + "|值符:" + 值符.ToString() + "|值使:" + 值使.ToString());

            // 名词解释
            DataTable dtConcept = DataFactory.ExecuteQuery("select 吉凶,描述 from 奇门遁甲概念 where 名称='{0}' and 类别='星'",this.九星[0].ToString() );
            AddQuery(dtConcept,this.九星[0].ToString());

            DataTable dtConceptDoor = DataFactory.ExecuteQuery("select 吉凶,描述 from 奇门遁甲概念 where 名称='{0}' and 类别='门'", this.八门.ToString());
            AddQuery(dtConceptDoor, this.八门.ToString());

            DataTable dtConceptGod = DataFactory.ExecuteQuery("select 吉凶,描述 from 奇门遁甲概念 where 名称='{0}' and 类别='神'", this.八神);
            AddQuery(dtConceptGod, this.八神);

            //奇仪对奇仪
            DataTable dtQYQY = DataFactory.ExecuteQuery("select 格局,描述 from 奇仪奇仪 where 天盘奇仪='{0}' and 地盘奇仪='{1}'", this.天盘奇仪[0].ToString(), this.地盘奇仪[0].ToString());
            AddQuery(dtQYQY, this.天盘奇仪[0] + "-" + this.地盘奇仪[0]);


            //奇宫格局
            DataTable dtQG = DataFactory.ExecuteQuery("select 格局,吉凶 from 奇宫格局 where 天盘三奇='{0}' and 地宫='{1}'", this.天盘奇仪[0].ToString(), this.所处之宫[0].ToString());
            AddQuery(dtQG, this.天盘奇仪[0] + "-" + this.所处之宫[0].ToString());


            //门 与三奇
            DataTable dtDoorQi = DataFactory.ExecuteQuery("select 含义 from 奇门对三奇 where 奇门='{0}' and 地盘三奇='{1}'", this.八门.ToString(), this.地盘奇仪[0].ToString());
            AddQuery(dtDoorQi, this.八门 + "-" + this.地盘奇仪[0]);

        }

        private void AddALine(String strNewLine)
        {
            textBox1.Text += "\r\n+" + strNewLine;
        }

        private void AddQuery(DataTable dt, String ItemName )
        {
            foreach (DataRow row in dt.Rows)
            {
                String AStringLine = ItemName;

                foreach (DataColumn field in dt.Columns)
                {
                    AStringLine += " " + row[field].ToString();
                }

                AddALine(AStringLine);
            }
        }
    }
}